"""
@author: Sergiy Tsymbalyuk
"""

from datetime import date

from pylons import url
from webhelpers.html import tags

from chowa.model.organization import District
from chowa.lib.helpers import *
from hrms.lib.base import Session

def children(employee):
    return ', '.join(unicode(child) for child in employee.children)

def select_timesheet_year():
    year = date.today().year
    return tags.select('year', [year], range(year-10, year+2))

def division_link(division):
    division_url = url(controller='organization',
                       action='division',
                       id=division.id)
    return tags.link_to(division.name, division_url)

def employee_link(employee):
    employee_url = url(controller='profile',
                       action='index',
                       id=employee.id)
    return tags.link_to(unicode(employee), employee_url)

def select_district(district_id):
    districts = Session.query(District).all()
    return tags.select('district', [district_id],
                       [('', '--')] + [(d.id, d.name) for d in districts])
